home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / Bars.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  14.9 KB  |  580 lines  |  [TEXT/CWIE]

  1. { Bars.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit Bars;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     EverythingEngine,
  21.     EverythingDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Bars        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mBarsHandle:        ControlHandle;
  30.         mScrollBarsHandle:        ControlHandle;
  31.         mStandard4Handle:        ControlHandle;
  32.         mGraphic4Handle:        ControlHandle;
  33.         mSliderHandle:        ControlHandle;
  34.         mTickMarksHandle:        ControlHandle;
  35.         mNonDirectionalHandle:        ControlHandle;
  36.         mLittleArrowsHandle:        ControlHandle;
  37.         mSpinnerHandle:        ControlHandle;
  38.         mVolumeControlHandle:        ControlHandle;
  39.         mJimSSliderHandle:        ControlHandle;
  40.         mProgressBarsHandle:        ControlHandle;
  41.         mStandard5Handle:        ControlHandle;
  42.         mIndeterminateHandle:        ControlHandle;
  43.         mChasingArrowsHandle:        ControlHandle;
  44.         mRectangleHandle:        ControlHandle;
  45.         mRoundRectHandle:        ControlHandle;
  46.         mBarberPoleHandle:        ControlHandle;
  47.         mRoundBarberHandle:        ControlHandle;
  48.  
  49.     {methods}
  50.         Procedure Initialize; Override;
  51.  
  52.         Procedure Open        (inDoc:        EverythingDoc;
  53.                              inData:    DDocData);
  54.         Procedure Close; Override;
  55.  
  56.         Procedure Control    (whichControl:    ControlHandle;
  57.                               whichPart:        integer;
  58.                              where:            Point); Override;
  59.         Procedure MouseIn    (where:            Point;
  60.                              modifiers:        integer); Override;
  61.         Procedure TypeIn    (charCode:        SInt16); Override;
  62.         Procedure ExitCurField; Override;
  63.         Procedure DataChanged    (inDataID:    longint); Override;
  64.         Procedure Resize; Override;
  65.         Procedure Scroll    (newValue:        integer;
  66.                              oldValue:        integer); Override;
  67.  
  68.         Function  GetEngine: EverythingEngine;
  69.  
  70. {$ifc false}
  71.         Procedure UpdateMenus; Override;
  72. {$endif}
  73.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  74.  
  75.         Procedure DoUndo;
  76.         Procedure DoCut;
  77.         Procedure DoCopy;
  78.         Procedure DoPaste;
  79.         Procedure DoClear;
  80.         Procedure DoSelectAll;
  81.         Procedure DoShowClipboard;
  82.  
  83.     end;
  84.  
  85. {----------}
  86. Procedure CreateBars    (inDoc:        EverythingDoc;
  87.                              inData:    DDocData);
  88.  
  89. {----------}
  90. Implementation
  91.  
  92. Uses
  93.     Globals,
  94.     ResourceDefs,
  95.     DoScrap,
  96.     Scrolling,
  97.     ControlUtils,
  98.     Miscellany;
  99.  
  100. const
  101.     kBarsPanel        = 1;
  102.     kScrollBarsLayer        = 2;
  103.     kStandard4Scroll        = 3;
  104.     kGraphic4Scroll        = 4;
  105.     kSliderScroll        = 5;
  106.     kTickMarksScroll        = 6;
  107.     kNonDirectionalScroll        = 7;
  108.     kLittleArrowsScroll        = 8;
  109.     kSpinnerScroll        = 9;
  110.     kVolumeControlScroll        = 10;
  111.     kJimSSliderScroll        = 11;
  112.     kProgressBarsLayer        = 12;
  113.     kStandard5Bar            = 13;
  114.     kIndeterminateBar            = 14;
  115.     kChasingArrowsBar            = 15;
  116.     kRectangleBar            = 16;
  117.     kRoundRectBar            = 17;
  118.     kBarberPoleBar            = 18;
  119.     kRoundBarberBar            = 19;
  120.  
  121. {----------}
  122. Procedure CreateBars (
  123.     inDoc:        EverythingDoc;
  124.     inData:        DDocData);
  125. var
  126.     winObj:        Bars;
  127. begin
  128.     winObj := nil;
  129.     New (winObj);
  130.  
  131.     if winObj <> nil then begin
  132.         winObj.Initialize;
  133.         winObj.Open (inDoc, inData);
  134.     end;
  135. end;
  136.  
  137. {----------}
  138. Procedure Bars.Initialize;
  139. begin
  140.     Inherited Initialize;
  141. end;
  142.  
  143. {----------}
  144. Function  Bars.GetEngine: EverythingEngine;
  145. begin
  146.     GetEngine := EverythingEngine (mDoc.mEngine);
  147. end;
  148.  
  149. {----------}
  150. Procedure Bars.Open (
  151.     inDoc:        EverythingDoc;
  152.     inData:        DDocData);
  153. var
  154.     window:        WindowPtr;
  155.     wftb:        Handle;
  156.     errCode:    OSErr;
  157. begin
  158.     mDoc := inDoc;
  159.     mData := inData;
  160.     mData.AddResponder (self);
  161.  
  162.     window := GetNewCWindow (WIND_Bars, nil, WindowPtr (-1));
  163.     if inDoc.mEngine.GetFilename <> '' then begin
  164.         SetWTitle (window, inDoc.mEngine.GetFilename);
  165.     end;
  166.     mWindow := window;
  167.     EverythingDoc (mDoc).mBarsPtr := window;
  168.  
  169.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  170.     SetWRefCon (window, ord4 (self));
  171.     SetPort (window);
  172.     SetInfo (window);
  173.  
  174.     wftb := GetResource ('Wftb', WIND_Bars);
  175.  
  176.     errCode := CreateRootControl (window, mRootControl);
  177.  
  178.     vScroll := nil;
  179.     hScroll := nil;
  180.  
  181.  
  182.     mBarsHandle := GetNewControl (CNTL_Bars, window);
  183.     SetWindowItemFont (mBarsHandle, wftb, 1);
  184.     SetControlValue (mBarsHandle, mData.GetBars);
  185.     SetLayerGroupValue (mBarsHandle, mData.GetBars);
  186.  
  187.     mScrollBarsHandle := GetNewControl (CNTL_ScrollBars, window);
  188.     errCode := EmbedControl (mScrollBarsHandle, mBarsHandle);
  189.     SetWindowItemFont (mScrollBarsHandle, wftb, 2);
  190.  
  191.     mStandard4Handle := GetNewControl (CNTL_Standard4, window);
  192.     errCode := EmbedControl (mStandard4Handle, mScrollBarsHandle);
  193.     SetWindowItemFont (mStandard4Handle, wftb, 3);
  194.     SetControlValue (mStandard4Handle, mData.GetStandard2);
  195.  
  196.     mGraphic4Handle := GetNewControl (CNTL_Graphic4, window);
  197.     errCode := EmbedControl (mGraphic4Handle, mScrollBarsHandle);
  198.     SetWindowItemFont (mGraphic4Handle, wftb, 4);
  199.     SetControlValue (mGraphic4Handle, mData.GetGraphic2);
  200.  
  201.     mSliderHandle := GetNewControl (CNTL_Slider, window);
  202.     errCode := EmbedControl (mSliderHandle, mScrollBarsHandle);
  203.     SetWindowItemFont (mSliderHandle, wftb, 5);
  204.     SetControlValue (mSliderHandle, mData.GetSlider);
  205.  
  206.     mTickMarksHandle := GetNewControl (CNTL_TickMarks, window);
  207.     errCode := EmbedControl (mTickMarksHandle, mScrollBarsHandle);
  208.     SetWindowItemFont (mTickMarksHandle, wftb, 6);
  209.     SetControlValue (mTickMarksHandle, mData.GetTickMarks);
  210.  
  211.     mNonDirectionalHandle := GetNewControl (CNTL_NonDirectional, window);
  212.     errCode := EmbedControl (mNonDirectionalHandle, mScrollBarsHandle);
  213.     SetWindowItemFont (mNonDirectionalHandle, wftb, 7);
  214.     SetControlValue (mNonDirectionalHandle, mData.GetNonDirectional);
  215.  
  216.     mLittleArrowsHandle := GetNewControl (CNTL_LittleArrows, window);
  217.     errCode := EmbedControl (mLittleArrowsHandle, mScrollBarsHandle);
  218.     SetWindowItemFont (mLittleArrowsHandle, wftb, 8);
  219.     SetControlValue (mLittleArrowsHandle, mData.GetLittleArrows);
  220.  
  221.     mSpinnerHandle := GetNewControl (CNTL_Spinner, window);
  222.     errCode := EmbedControl (mSpinnerHandle, mScrollBarsHandle);
  223.     SetWindowItemFont (mSpinnerHandle, wftb, 9);
  224.     SetControlValue (mSpinnerHandle, mData.GetSpinner);
  225.  
  226.     mVolumeControlHandle := GetNewControl (CNTL_VolumeControl, window);
  227.     errCode := EmbedControl (mVolumeControlHandle, mScrollBarsHandle);
  228.     SetWindowItemFont (mVolumeControlHandle, wftb, 10);
  229.     SetControlValue (mVolumeControlHandle, mData.GetVolumeControl);
  230.  
  231.     mJimSSliderHandle := GetNewControl (CNTL_JimSSlider, window);
  232.     errCode := EmbedControl (mJimSSliderHandle, mScrollBarsHandle);
  233.     SetWindowItemFont (mJimSSliderHandle, wftb, 11);
  234.     SetControlValue (mJimSSliderHandle, mData.GetJimSSlider);
  235.  
  236.     mProgressBarsHandle := GetNewControl (CNTL_ProgressBars, window);
  237.     errCode := EmbedControl (mProgressBarsHandle, mBarsHandle);
  238.     SetWindowItemFont (mProgressBarsHandle, wftb, 12);
  239.  
  240.     mStandard5Handle := GetNewControl (CNTL_Standard5, window);
  241.     errCode := EmbedControl (mStandard5Handle, mProgressBarsHandle);
  242.     SetWindowItemFont (mStandard5Handle, wftb, 13);
  243.     SetControlValue (mStandard5Handle, mData.GetStandard3);
  244.  
  245.     mIndeterminateHandle := GetNewControl (CNTL_Indeterminate, window);
  246.     errCode := EmbedControl (mIndeterminateHandle, mProgressBarsHandle);
  247.     SetWindowItemFont (mIndeterminateHandle, wftb, 14);
  248.     SetControlValue (mIndeterminateHandle, mData.GetIndeterminate);
  249.     SetIndeterminateState (mIndeterminateHandle, true);
  250.  
  251.     mChasingArrowsHandle := GetNewControl (CNTL_ChasingArrows, window);
  252.     errCode := EmbedControl (mChasingArrowsHandle, mProgressBarsHandle);
  253.     SetWindowItemFont (mChasingArrowsHandle, wftb, 15);
  254.     SetControlValue (mChasingArrowsHandle, mData.GetChasingArrows);
  255.  
  256.     mRectangleHandle := GetNewControl (CNTL_Rectangle, window);
  257.     errCode := EmbedControl (mRectangleHandle, mProgressBarsHandle);
  258.     SetWindowItemFont (mRectangleHandle, wftb, 16);
  259.     SetControlValue (mRectangleHandle, mData.GetRectangle);
  260.  
  261.     mRoundRectHandle := GetNewControl (CNTL_RoundRect, window);
  262.     errCode := EmbedControl (mRoundRectHandle, mProgressBarsHandle);
  263.     SetWindowItemFont (mRoundRectHandle, wftb, 17);
  264.     SetControlValue (mRoundRectHandle, mData.GetRoundRect);
  265.  
  266.     mBarberPoleHandle := GetNewControl (CNTL_BarberPole, window);
  267.     errCode := EmbedControl (mBarberPoleHandle, mProgressBarsHandle);
  268.     SetWindowItemFont (mBarberPoleHandle, wftb, 18);
  269.     SetControlValue (mBarberPoleHandle, mData.GetBarberPole);
  270.  
  271.     mRoundBarberHandle := GetNewControl (CNTL_RoundBarber, window);
  272.     errCode := EmbedControl (mRoundBarberHandle, mProgressBarsHandle);
  273.     SetWindowItemFont (mRoundBarberHandle, wftb, 19);
  274.     SetControlValue (mRoundBarberHandle, mData.GetRoundBarber);
  275.  
  276.     SetLayerGroupValue (mBarsHandle, mData.GetBars);
  277.  
  278.     errCode := AdvanceKeyboardFocus (window);
  279.  
  280.     ShowWindow (window);
  281. end;
  282.  
  283. {----------}
  284. Procedure Bars.Close;
  285. begin
  286.     mData.RemoveResponder (self);
  287.  
  288.     EverythingDoc (mDoc).mBarsPtr := nil;
  289.     SetInfo (nil);
  290.     HideWindow (mWindow);
  291.     DisposeWindow (mWindow);
  292.  
  293.     Dispose (self);
  294. end;
  295.  
  296. {----------}
  297. Procedure Bars.Control (
  298.     whichControl:    ControlHandle;
  299.     whichPart:        integer;
  300.     where:            Point);
  301. var
  302.     bounds:            Rect;
  303.     newValue:        integer;
  304.     partcode:        SInt16;
  305. begin
  306.     ExitCurField ();
  307.  
  308.     if whichControl = mBarsHandle then begin
  309.         if TrackClick (mBarsHandle, where) then begin
  310.             mData.SetBars (GetControlValue (mBarsHandle));
  311.         end;
  312.     end;
  313.     if whichControl = mStandard4Handle then begin
  314.         partCode := HandleControlClick (mStandard4Handle, where, curEvent.modifiers, nil);
  315.         mData.SetStandard2 (GetControlValue (mStandard4Handle));
  316.     end;
  317.     if whichControl = mGraphic4Handle then begin
  318.         partCode := HandleControlClick (mGraphic4Handle, where, curEvent.modifiers, nil);
  319.         mData.SetGraphic2 (GetControlValue (mGraphic4Handle));
  320.     end;
  321.     if whichControl = mSliderHandle then begin
  322.         partCode := HandleControlClick (mSliderHandle, where, curEvent.modifiers, nil);
  323.         mData.SetSlider (GetControlValue (mSliderHandle));
  324.     end;
  325.     if whichControl = mTickMarksHandle then begin
  326.         partCode := HandleControlClick (mTickMarksHandle, where, curEvent.modifiers, nil);
  327.         mData.SetTickMarks (GetControlValue (mTickMarksHandle));
  328.     end;
  329.     if whichControl = mNonDirectionalHandle then begin
  330.         partCode := HandleControlClick (mNonDirectionalHandle, where, curEvent.modifiers, nil);
  331.         mData.SetNonDirectional (GetControlValue (mNonDirectionalHandle));
  332.     end;
  333.     if whichControl = mLittleArrowsHandle then begin
  334.         partCode := HandleControlClick (mLittleArrowsHandle, where, curEvent.modifiers, nil);
  335.         mData.SetLittleArrows (GetControlValue (mLittleArrowsHandle));
  336.     end;
  337.     if whichControl = mSpinnerHandle then begin
  338.         partCode := HandleControlClick (mSpinnerHandle, where, curEvent.modifiers, nil);
  339.         mData.SetSpinner (GetControlValue (mSpinnerHandle));
  340.     end;
  341.     if whichControl = mVolumeControlHandle then begin
  342.         partCode := HandleControlClick (mVolumeControlHandle, where, curEvent.modifiers, nil);
  343.         mData.SetVolumeControl (GetControlValue (mVolumeControlHandle));
  344.     end;
  345.     if whichControl = mJimSSliderHandle then begin
  346.         partCode := HandleControlClick (mJimSSliderHandle, where, curEvent.modifiers, nil);
  347.         mData.SetJimSSlider (GetControlValue (mJimSSliderHandle));
  348.     end;
  349. end;
  350.  
  351. {----------}
  352. Procedure Bars.DataChanged (
  353.     inDataID:        longint);
  354. begin
  355.     if inDataID = idBars then begin
  356.         SetControlValue (mBarsHandle, mData.GetBars);
  357.         SetLayerGroupValue (mBarsHandle, mData.GetBars);
  358.     end;
  359.     if inDataID = idStandard2 then begin
  360.         SetControlValue (mStandard4Handle, mData.GetStandard2);
  361.     end;
  362.     if inDataID = idGraphic2 then begin
  363.         SetControlValue (mGraphic4Handle, mData.GetGraphic2);
  364.     end;
  365.     if inDataID = idSlider then begin
  366.         SetControlValue (mSliderHandle, mData.GetSlider);
  367.     end;
  368.     if inDataID = idTickMarks then begin
  369.         SetControlValue (mTickMarksHandle, mData.GetTickMarks);
  370.     end;
  371.     if inDataID = idNonDirectional then begin
  372.         SetControlValue (mNonDirectionalHandle, mData.GetNonDirectional);
  373.     end;
  374.     if inDataID = idLittleArrows then begin
  375.         SetControlValue (mLittleArrowsHandle, mData.GetLittleArrows);
  376.     end;
  377.     if inDataID = idSpinner then begin
  378.         SetControlValue (mSpinnerHandle, mData.GetSpinner);
  379.     end;
  380.     if inDataID = idVolumeControl then begin
  381.         SetControlValue (mVolumeControlHandle, mData.GetVolumeControl);
  382.     end;
  383.     if inDataID = idJimSSlider then begin
  384.         SetControlValue (mJimSSliderHandle, mData.GetJimSSlider);
  385.     end;
  386.     if inDataID = idStandard3 then begin
  387.         SetControlValue (mStandard5Handle, mData.GetStandard3);
  388.     end;
  389.     if inDataID = idIndeterminate then begin
  390.         SetControlValue (mIndeterminateHandle, mData.GetIndeterminate);
  391.     end;
  392.     if inDataID = idChasingArrows then begin
  393.         SetControlValue (mChasingArrowsHandle, mData.GetChasingArrows);
  394.     end;
  395.     if inDataID = idRectangle then begin
  396.         SetControlValue (mRectangleHandle, mData.GetRectangle);
  397.     end;
  398.     if inDataID = idRoundRect then begin
  399.         SetControlValue (mRoundRectHandle, mData.GetRoundRect);
  400.     end;
  401.     if inDataID = idBarberPole then begin
  402.         SetControlValue (mBarberPoleHandle, mData.GetBarberPole);
  403.     end;
  404.     if inDataID = idRoundBarber then begin
  405.         SetControlValue (mRoundBarberHandle, mData.GetRoundBarber);
  406.     end;
  407. End;
  408.  
  409. {----------}
  410. Procedure Bars.MouseIn (
  411.     where:            Point;
  412.     modifiers:        integer);
  413. var
  414.     bounds:            Rect;
  415. begin
  416. end;
  417.  
  418. {----------}
  419. Procedure Bars.ExitCurField;
  420. var
  421.     errCode:    OSErr;
  422.     focus:        ControlHandle;
  423. begin
  424.     errCode := GetKeyboardFocus (mWindow, focus);
  425.  
  426.     if focus = nil then begin
  427.         { nothing to exit }
  428.  
  429.     end;
  430.     inherited ExitCurField;
  431. end;
  432.  
  433. {----------}
  434. Procedure Bars.TypeIn (
  435.     charCode:    SInt16);
  436. var
  437.     ch:            char;
  438.     errCode:    OSErr;
  439.     focus:        ControlHandle;
  440.     keyCode:    SInt16;
  441.     partcode:    SInt16;
  442. begin
  443.     errCode := GetKeyboardFocus (mWindow, focus);
  444.  
  445.     ch := chr (charCode);
  446.     if (ch = charEnter)
  447.     |  (ch = charReturn) then begin
  448.         ExitCurField;
  449.     end else if ch = charEsc then begin
  450.     end else if ch = charTab then begin
  451.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  452.     end else if focus <> nil then begin
  453.         keyCode := BAnd (curEvent.message, keyCodeMask);
  454.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  455.         mDoc.mEngine.SetDirty;
  456.     end else begin
  457.         SysBeep (1);
  458.     end;
  459. end;
  460.  
  461. {----------}
  462. Procedure Bars.Resize;
  463. begin
  464.     { application-specific code to resize items in window }
  465. end;
  466.  
  467. {----------}
  468. Procedure Bars.Scroll (
  469.     newValue:    integer;
  470.     oldValue:    integer);
  471. begin
  472.     { application-specific code to scroll window }
  473.     if gWhichScroll = vScroll then begin
  474.     end else begin    { horizontal }
  475.     end;
  476. end;
  477.  
  478. {----------}
  479. Procedure Bars.DoUndo;
  480. begin
  481. end; {DoUndo}
  482.  
  483. {----------}
  484. Procedure Bars.DoCut;
  485. var
  486.     curTE:        TEHandle;
  487. begin
  488.     curTE := GetCurTE ();
  489.  
  490.     if curTE <> nil then begin
  491.         TECut (curTE);
  492.         mDoc.mEngine.SetDirty;
  493.         scrapDirty := true;
  494.     end;
  495. end; {DoCut}
  496.  
  497. {----------}
  498. Procedure Bars.DoCopy;
  499. var
  500.     curTE:        TEHandle;
  501. begin
  502.     curTE := GetCurTE ();
  503.  
  504.     if curTE <> nil then begin
  505.         TECopy (curTE);
  506.         scrapDirty := true;
  507.     end;
  508. end; {DoCopy}
  509.  
  510. {----------}
  511. Procedure Bars.DoPaste;
  512. var
  513.     curTE:        TEHandle;
  514. begin
  515.     curTE := GetCurTE ();
  516.  
  517.     if curTE <> nil then begin
  518.         TEPaste (curTE);
  519.         mDoc.mEngine.SetDirty;
  520.     end;
  521. end; {DoPaste}
  522.  
  523. {----------}
  524. Procedure Bars.DoClear;
  525. var
  526.     curTE:        TEHandle;
  527. begin
  528.     curTE := GetCurTE ();
  529.  
  530.     if curTE <> nil then begin
  531.         TEDelete (curTE);
  532.         mDoc.mEngine.SetDirty;
  533.     end;
  534. end; {DoClear}
  535.  
  536. {----------}
  537. Procedure Bars.DoSelectAll;
  538. var
  539.     curTE:        TEHandle;
  540. begin
  541.     curTE := GetCurTE ();
  542.  
  543.     if curTE <> nil then begin
  544.         TESetSelect (0, 32767, curTE);
  545.     end;
  546. end; {DoSelectAll}
  547.  
  548. {----------}
  549. Procedure Bars.DoShowClipboard;
  550. begin
  551. end; {DoShowClipboard}
  552.  
  553. {----------}
  554. Function Bars.DoCommand (
  555.     inCommand:        longint): Boolean;
  556. begin
  557.     DoCommand := true;
  558.     case inCommand of
  559.         cmdUndo:
  560.                 DoUndo;
  561.         cmdCut:
  562.                 DoCut;
  563.         cmdCopy:
  564.                 DoCopy;
  565.         cmdPaste:
  566.                 DoPaste;
  567.         cmdClear:
  568.                 DoClear;
  569.         cmdSelectAll:
  570.                 DoSelectAll;
  571.         cmdShowClipboard:
  572.                 DoShowClipboard;
  573.  
  574.         otherwise
  575.                 DoCommand := false;
  576.     end; {case}
  577. end;
  578.  
  579. end.
  580.